package org.example.dao;

import org.example.model.Users;
import org.example.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 专门针对学生表的数据库访问对象
 */
public class UsersDao {
    public int insert(Users record){
        Connection connection = null;
        PreparedStatement statement = null;

        try {
            connection = DBUtil.getConnection();
            String sql = "insert into users(name) values (?)";
            statement = connection.prepareStatement(sql);
            statement.setString(1,record.getName());
            int i = statement.executeUpdate();
            return i;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
           DBUtil.close(null,statement,connection);
        }

    }
}
